import {Component, OnInit} from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
import {Events, ModalController, NavController, NavParams, Platform} from '@ionic/angular';
import {SafeResourceUrl} from '@angular/platform-browser/src/security/dom_sanitization_service';

@Component({
  selector: 'app-iframe-page',
  templateUrl: './iframe-page.component.html',
  styleUrls: ['./iframe-page.component.scss']
})
export class IframePageComponent implements OnInit {

  public url: SafeResourceUrl;
  public title: string;
  private topic: string;
  public scrolling = 'yes';

  constructor(private navCtrl: NavController,
              private modalCtrl: ModalController,
              private navParams: NavParams,
              private events: Events,
              private sanitizer: DomSanitizer,
              private platform: Platform
  ) {
    if (this.platform.is('ios')) {
      this.scrolling = 'no'; // ios下iframe禁止滚动
    }
  }

  ngOnInit() {
    this.title = this.navParams.data['title'] || '盛融贷';
    this.url = this.sanitizer.bypassSecurityTrustResourceUrl(this.navParams.data['url']); // 转为安全链接对象
    this.topic = this.navParams.data['topic'];
    console.log('iframePage安全链接:', this.url);
  }

  closeModal() {
    this.modalCtrl.dismiss()
      .then(() => {
        if (this.topic) {
          this.events.publish(this.topic);
        }
      });
  }

}
